<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%
	String basePath = request.getContextPath() + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<div class="wrapper wrapper-content">
	<div class="col-xs-12">
		<div class="ibox">
			<div class="ibox-content">
				<form name="FormPost" id="standcode-addOrUpdate-form"
					class="form-horizontal" method="post" action="" style="width: 100%">
					<!--操作类型  -->
					<input type="hidden" value="${type }" name="type">
					<!--主键  -->
						<input type="hidden" value="${empty standcode?'':standcode.stdCodeId }"
							name="stdCodeId">
					<div class="form-group">
						<label class="col-sm-4 control-label">代码类别:</label>
						<div class="col-sm-7">
								<input type="text" name="stdCatId" id="stdCatId" 
									value="${empty standcode?'':standcode.stdCatId }"
									class="form-control" datatype="*" nullmsg="请输代码类别!" required />
									<span style="font-family: Arial, Helvetica, sans-serif; color: #ff0000;" id="check"></span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-4 control-label">标准代码:</label>
						<div class="col-sm-7">
								<input type="text" name="stdCode" id="stdCode1" onkeyup="value=value.replace(/[^\d|a-zA-Z]/g,'')"
									value="${empty standcode?'':standcode.stdCode }" class="form-control"
									datatype="*" nullmsg="标准代码!" required />
									<span style="font-family: Arial, Helvetica, sans-serif; color: #ff0000;" id="check1"></span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-4 control-label">标准名称:</label>
						<div class="col-sm-7">
								<input type="text" name="stdCodeName" id="stdCodeName"
									value="${empty standcode?'':standcode.stdCodeName }" class="form-control"
									datatype="*" nullmsg="标准名称!" required />
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-4 control-label">代码描述:</label>
						<div class="col-sm-7">
								<input type="text" name="stdCodeDesc" id="stdCodeDesc"
									value="${empty standcode?'':standcode.stdCodeDesc }" class="form-control"
									datatype="*" nullmsg="代码描述!" required />
						</div>
					</div>					
					<div class="form-group">
						<label class="col-sm-4 control-label">有效标志:</label>
						<div class="col-sm-7">
<%-- 								<input type="text" name="validFlag"
									value="${empty standcode?'':standcode.validFlag }"
									id="validFlag" class="form-control" datatype="*"
									nullmsg="有效标志!" required /> --%>
								<select name="validFlag" id="validFlag" class="form-control" datatype="*" >
									<c:if test="${standcode.validFlag ==1 || empty standcode.validFlag}">
										<option value="1">是</option>
									</c:if>
									<c:if test="${standcode.validFlag ==0 || empty standcode.validFlag}">
										<option value="0">否</option>
									</c:if>
								</select>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
<script>
//校验
$("#standcode-addOrUpdate-form").validate({
	rules : {
		stdCatId : {
			required : true
		},
		stdCode : {
			required : true
		},
		stdCodeName : {
			required : true
		},
		stdCodeDesc : {
			required : true
		},
		validFlag : {
			required : true
		}
	},
	messages : {
		stdCatId : {
			required : "请输入代码类别"
		},
		stdCode : {
			required : "请输入标准代码",
		},
		stdCodeName : {
			required : "请输入标准代码名称",
		},
		stdCodeDesc : {
			required : "请输入标准代码描述",
		},
		validFlag : {
			required : "请输入有效标识",
		}
	}, 
	ignore: ":hidden:not(.chosen-select)",
	submitHandler : function(form) {
		$("#standcode-addOrUpdate-form").ajaxSubmit({
			type : 'post',
			url : "<%=basePath%>rest/codemanager/standcode/saveOrEdit",
			success : function(data) {
				if (data.code == 1) {
					layer.open({
						type: 0,
						time: 800,
						icon: 1,
						content: data.msg,
						btn: 0,
						title: false,
						closeBtn: false,
						skin: 'layui-layer-rim',
						end: function(){
	                        layer.closeAll();
	                        //location.reload();
	                    }
					});
              } else {
           	    layer.msg(data.msg,{
           			time: 2000,
           			anim:6
           		});
              }
				var params = jQuery("#search-form").serializeJson();
				$("#table").bootstrapTable("refresh", {query: params});
			}
		});
	}
	
});

$("#stdCatId").click(function(){
    var params = 
	{
		"type": 1,
		"title": "<i class=\"fa fa-desktop\"></i>&nbsp;添加",
		"zIndex": 199206,
		"shade": [0.5,"#000"],
		"closeBtn": 1,
		"maxmin": false,
		"width": "1200px",
		"height": "",
		"btn": ["<i class=\"ace-icon fa fa-floppy-o middle-120\"></i>&nbsp;确定",
		"<i class=\"ace-icon fa fa-times-circle middle-120\"></i>&nbsp;关 闭"],
		"btnAlign": "c",
		"reloadUrl": false,
		"formId": "datamodel-form",
		"success": null,
		"area": ["900px","500px"],
		"yes" : function(){
			var select = $("#table1").bootstrapTable("getSelections");
			$("#stdCatId").val(select[0].stdCatType);
			layer.close(layer.index);
		}
    }
    $.ajax({
    	url:"<%=basePath%>rest/codemanager/standcode/toCodeTypeList",
    	async:false,
    	success:function(data){
    		params.content = data;
    	}
    });
    layer.open(params);
})

/* $(document).ready(function(){
	  $("#stdCode1").blur(function(){
	    var stdCode1 = $("#stdCode1").val();
	    var re =/^[0-9a-zA-Z]*$/g;
	    if(!re.test(stdCode1)){
	    	alert("请输入正确的标准代码！")
	    	return false;
	    }
	  });
	}); */
$(document).on('click', '.layui-layer-btn0', function(){
	$("#standcode-addOrUpdate-form").valid();
})
</script>